package com.example.Servlet;

import com.alibaba.fastjson.JSON;
import com.example.Function.DataBaseOp;
import com.example.Object.Question;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
/**
 * @author echo
 *保存错题
 */
@WebServlet("/SavaErrorList")
public class SaveErrorList extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String email = req.getParameter("email");
        String code = req.getParameter("code");
        String data = req.getParameter("data");

        List<Question> questions = JSON.parseArray(data, Question.class);
        int i = DataBaseOp.insertErrorQuestion(questions, DataBaseOp.getErrorCode(code),email);
        if(i != 0){
            PrintWriter out = resp.getWriter();
            Gson gson = new Gson();
            out.println(gson.toJson(true));
        }

    }
}
